<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   <style>
        *{margin: 0;padding: 0;}
        
        .stars{
            width: 200px;
            height: 40px;
            list-style: none;
            margin: 0;
            line-height: 36px;
            color: #ccc;
            margin-left: 20px;
            float: left;
        }
        .stars span{
            font-size: 30px;
            margin-left: 10px;
        }
        .stars span:after{
            content:'☆';
        }
        stars .show:after,.stars .show2:after{
            content:'★';
        }
       .info{
           float:left;
           width: 60px;
           height: 30px;
           background-color: #e15671;
           border-radius: 5px;
           color: #fff;
           text-align: center;
           line-height: 36px;
           display: none;
       }
       .show{
           color:red;
       }
       .show2{
           color: #e15671;
       }
   </style>
</head>
<body>
    <div class="stars">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
    <div class="info">优秀</div>


    <script>
        var stars=document.querySelectorAll(".stars span");
        var info=document.querySelector(".info");

        var grades=["极差","差","一般","良好","优秀"];
        var active=-1;

        for(var i=0;i<stars.length;i++){
            stars[i].index=i;
            stars[i].onmouseover=function(){setStar(this.index);};
            stars[i].onmouseout=function(){setStar(active);};
            stars[i].onclick=setClick;
        }

         
        function setStar(nub){
            var name='';
            name=nub<2 ?'show':'show2';
            for(var i=0;i<stars.length;i++){
                stars[i].className=i<=nub?name:'';
            }
            info.style.display=nub<0 ?'none':'block';
            info.innerHTML=grades[nub];
        }
        


        function setClick(){
            active=this.index;
        }
    </script>
</body>

     
</html>